package com.azirkxs.clothes.cys.controller;

import com.azirkxs.clothes.common.vo.ArmoireCreate;
import com.azirkxs.clothes.common.vo.ArmoireEditRequest;
import com.azirkxs.clothes.common.vo.Result;
import com.azirkxs.clothes.cys.entity.Armoire;
import com.azirkxs.clothes.cys.entity.Clothes;
import com.azirkxs.clothes.cys.mapper.ClothesMapper;
import com.azirkxs.clothes.cys.service.IArmoireService;
import com.azirkxs.clothes.cys.service.IClothesService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author azirkxs
 * @since 2023-04-09
 */
@RestController
@RequestMapping("/armoire")
public class ArmoireController {

    @Autowired
    IArmoireService iArmoireService;

    @GetMapping("/armoireTag")
    public Result<Map<String,Object>> armoireTag(@RequestParam("armoireId") Integer armoire_id){
        Map<String,Object> data = iArmoireService.getArmoireTagsByArmoireId(armoire_id);
        if(data!=null){
            return Result.success(data);
        }

        return Result.fail(20003,"获取信息失败");
    }

    @PostMapping("/armoireEdit")
    public Result<Map<String,Object>> armoireEdit(@RequestBody ArmoireEditRequest request) {
        iArmoireService.updateArmoire(request.getArmoireId(), request.getName(), request.getTags());
        System.out.println(request.getArmoireId());
        return Result.success("编辑成功");
    }

    @PostMapping("/armoireCreate")
    public Result<Map<String,Object>> create(@RequestBody ArmoireCreate request) {
        iArmoireService.createArmoire(request.getName(), request.getTags(),request.getUserId());
        return Result.success("创建成功");
    }

    @PostMapping("/armoireDelete")
    public Result<Map<String,Object>> delete(@RequestParam("armoireId") Integer id) {
        iArmoireService.deleteArmoire(id);
        return Result.success("删除成功");
    }


}
